package com.element.oauth2.constant;

import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;

/**
 * @auther WuJun.Zhang
 * @date 2022/2/18 下午8:55
 */
public interface SecurityParams {

    /**
     * 解析请求参数 client_id
     */
    String CLIENT_ID = "app_id";

    /**
     * 解析请求参数 app_secret
     */
    String CLIENT_SECRET = "app_secret";

    /**
     * 解析请求参数 user_name
     */
    String USER_NAME = "user_name";

    /**
     * 解析请求参数 password
     */
    String PASSWORD = "password";

    /**
     * 用户信息
     */
    String USER_INFO = "user_info";

    /**
     * 解析请求参数 state
     */
    String STATE = "state";

    /**
     * 解析请求参数 redirect_uri
     */
    String REDIRECT_URL = "redirect_url";

    /**
     * 解析请求参数 response_type
     */
    String RESPONSE_TYPE = "response_type";

    /**
     * 自定义获取token码类型
     */
    String RESPONSE_TYPE_TOKEN = "token";

    /**
     * 自定义获取code码类型
     */
    String RESPONSE_TYPE_CODE = "code";

    /**
     * 解析请求参数 grant_type
     */
    String GRANT_TYPE = "grant_type";

    /**
     * 解析请求参数 scope
     */
    String SCOPE = "scope";

    /**
     * scope类型为openId
     */
    String OPEN_ID = "open_id";

    /**
     * 返回用户信息
     */
    String RESPONSE_USER_ID = "user_id";

    /**
     * 自定义回调code
     */
    String APP_CODE = "app_code";

    /**
     * 授权信息存储
     */
    String SPRING_SECURITY_AUTH_KEY = "spring:security:token:auth:";

    /**
     * token存储
     */
    String SPRING_SECURITY_TOKEN_KEY = "spring:security:token:";

    /**
     * 确认信息存储
     */
    String SPRING_SECURITY_CONSENT_KEY = "spring:security:consent:";

    /**
     * 用户token信息
     *
     * @param authorization 授权信息
     * @param userName      用户名
     */
    static String SPRING_SECURITY_USER_TOKEN_KEY(OAuth2Authorization authorization, String userName) {
        return "spring:security:token:user:" + authorization.getRegisteredClientId() + ":" + authorization.getAuthorizationGrantType().getValue() + ":" + userName;
    }

    static String SPRING_SECURITY_USER_TOKEN_KEY(String appId, String grantType, String userName) {
        return "spring:security:token:user:" + appId + ":" + grantType + ":" + userName;
    }

    /**
     * 应用拓展字段(IP地址集合)
     */
    String CLIENT_EXPAND_IP = "client_expand_ip";

    /**
     * 授权页面地址
     */
    String CONSENT_PAGE = "/login/confirm_access";

    String TOKEN_ENDPOINT_URL = "/oauth/token";

    String AUTHORIZATION_ENDPOINT_URL = "/oauth/authorize";

    String TOKEN_INTROSPECTION_URL = "/oauth/introspect";

    String TOKEN_REVOCATION_URL = "/oauth/revoke";

    String LOGIN_PAGE = "/login/login";
}